package com.across.connect.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.across.connect.home.MyUserHome;
import com.across.connect.model.MyUser;
import com.across.connect.util.CookieManager;
import com.across.connect.util.XnConnect;

public class CallBackAction extends Action{
	
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)throws 
			Exception{
		
		try {
			String xn_sig_session_key = request
					.getParameter("xn_sig_session_key");
			//String xn_sig_api_key = request.getParameter("xn_sig_api_key");
			int xn_sig_user = Integer.parseInt(request
					.getParameter("xn_sig_user"));
			//保存用户的SessionKey信息
			XnConnect.setXiaoneiSessionKey(xn_sig_user, xn_sig_session_key);
			/**
			 * 当一个新用户通过Connect与站点建立联系后，校内会将用户数据POST到这个CallbackURL上，通知站点有新用户进来了
			 */
			System.err.println("zrj: xn_sig_user-"+xn_sig_user);
			MyUser host = MyUserHome.getInstance().createFromXiaoneiUID(
					xn_sig_user);
			if (host != null) {
				System.err.println("zrj: emailhash-"+host.getEmailHash()+"--xnid--"+host.getXnuid());
				CookieManager.getInstance().saveCookie(response, "swimmingID",
						String.valueOf(host.getId()));
			}
		} catch (Exception e) {
		}
		return null;
	}

}
